package com.shuw.com.beingfortextproject;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

import com.shuw.com.beingfortextproject.activity.AutoFlowActivity;
import com.shuw.com.beingfortextproject.activity.DialogActivity;
import com.shuw.com.beingfortextproject.activity.ResidentActivity;
import com.shuw.com.beingfortextproject.activity.SendMailActivity;
import com.shuw.com.beingfortextproject.activity.TabTestActivity;
import com.shuw.com.beingfortextproject.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {

	@BindView(R.id.webView)
	WebView webView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		ButterKnife.bind(this);
		initView();
	}

	/**
	 * @blog http://www.browsersync.cn/
	 */
	private void initView() {
		webView.getSettings().setJavaScriptEnabled(true);


		webView.setWebChromeClient(new WebChromeClient() {
			@Override
			public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
				System.out.println("message ====> " + message);
				List<String> urls = new ArrayList();
				List<String> strings = new ArrayList();
				String[] picList = message.split(",");
				int length = picList.length;
				for (int i = 0; i < length - 2; i++) {
					urls.add(picList[i]);
				}
				strings.add(picList[length - 2]);
				int position = Integer.parseInt(picList[length - 1]);

				for (int i = 0; i < length - 2; i++) {
					System.out.println("图片地址--------------> " + urls.get(i));
				}
				System.out.println("文字说明------------> " + strings.get(0));
				System.out.println("位置是---------------> " + position);

				result.cancel();
				return true;
			}

		});

		webView.loadUrl("http:192.168.0.115/Oil_CMS/mobile/marketdetail.php?id=15&from=app");
	}

	@OnClick({R.id.fButton, R.id.tabButton,R.id.sendEmailBt,R.id.dialogBtn,R.id.serviceBtn})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.fButton:
				startActivity(new Intent(this, AutoFlowActivity.class));
				break;
			case R.id.tabButton:
				startActivity(new Intent(this, TabTestActivity.class));
				break;
			case R.id.sendEmailBt:
				startActivity(new Intent(this, SendMailActivity.class));
				break;
			case R.id.dialogBtn:
				startActivity(new Intent(this, DialogActivity.class));
				break;
			case R.id.serviceBtn:
				startActivity(new Intent(this, ResidentActivity.class));
				break;
		}
	}

	/*@OnClick(R.id.fButton)
	public void onClick() {
		startActivity(new Intent(this, AutoFlowActivity.class));
	}*/


}
